import asyncio
import aioredis


a = []


async def connect_uri():
    conn = await aioredis.create_redis_pool('redis://47.103.89.53:6379/9')
    return conn


async def close(redis):
    redis.close()
    await redis.wait_closed()


async def redis_pool(loop, i):
    redis = await connect_uri()
    await redis.set(i, i)
    val = await redis.get(i, encoding='utf-8')
    a.append(val)

    await close(redis)


if __name__ == '__main__':
    import time
    start = time.time()
    # loop = asyncio.get_event_loop()
    # tasks = [redis_pool(loop, str(i)) for i in range(1000)]
    # results = loop.run_until_complete(asyncio.gather(*tasks))
    # print(len(a))

    import redis
    POOL = redis.ConnectionPool(host='47.103.89.53', port=6379, db=10)
    cache = redis.Redis(connection_pool=POOL)

    for i in range(1000):
        cache.set(f'{i}', f'{i}')
        a.append(i)
    print(a)
    print(time.time() - start)